<template>
  <div class="common-page f-c">
    <el-form inline>
      <el-form-item label="课程">
        <el-select v-model="searchParams.course_id">
          <el-option v-for="item in courseList" :key="item.id" :value="item.id" :label="item.name" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="margin-left: 15px" @click="onSearch">搜索</el-button>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table
        v-loading="loading"
        style="width: 100%"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" align="center" label="序号" />
        <el-table-column
          v-for="item in columns"
          :key="item.prop"
          :sortable="item.sortable"
          :prop="item.prop"
          :label="item.label"
          align="center"
        />
      </el-table>
    </div>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http } from '@/api'
import { mapGetters } from 'vuex'
import { datetime } from '@/utils'
export default {
  name: 'Page',
  computed: {
    ...mapGetters(['schoolList', 'courseList', 'classList', 'categoryList'])
  },
  mixins: [crud],
  data() {
    return {
      request: http.score,
      searchParams: {
        course_id: ''
      },
      columns: [
        { prop: 'student.student_name', label: '学生姓名' },
        { prop: 'total', label: '总分', sortable: true },
        { prop: 'score1', label: '平时成绩' },
        { prop: 'score2', label: '期末成绩' }
      ],
      studentList: [],
      teacherList: []
    }
  },
  methods: {
    initData() {
      if (!this.courseList.length) return this.$message.warning('请选择课程')
      if (!this.searchParams.course_id) {
        this.searchParams.course_id = this.courseList[0].id
      }
      this.request.page({
        ...this.getQueryParams(),
        pageSize: 99999
      }
      ).then(res => {
        this.loading = false
        this.totalSize = res.total
        const tableData = res.rows
        tableData.forEach(el => {
          if (el.created_at) {
            el.created_at = datetime(el.created_at)
          }
          el.total = (parseFloat(el.score1) * 0.4 + parseFloat(el.score2) * 0.6).toFixed(2)
        })
        this.tableData = tableData
      })
    }
  }
}
</script>

<style scoped lang="scss">
.common-page {
  height:  100%;
}
</style>
